// pages/encyclopedia/more.js
const { getMedicineData, getMedicineLabel } = require('../../api/encyclopedia')
let app =  getApp();
Page({
  data:{
    mainActiveIndex: 0,
    activeId: null,
    activeKey:0,
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '疾病找药', //导航栏 中间的标题
      white: false, // 是就显示白的，不是就显示黑的。
      bgColor:'#B7EADE' // 加个背景 不加就是没有
    },
    height:app.globalData.height * 2-10
  },
  onLoad(option){
    let items;
    let labelItems;

    getMedicineData().then(res=>{
      items = Object.assign({},res.Disease_Left_List);
      this.setData({items,activeKey:option.id-1})
    }),

    getMedicineLabel(option.label).then(res=>{
      labelItems = Object.assign({}, res.Disease_Left_Right);
      this.setData({labelItems})
    })
  },

  onClickNav({ detail = {} }) {
    this.setData({
      mainActiveIndex: detail.index || 0,
    });
  },

  onChange(e){
    let label = this.data.items[e.detail].label
    let labelItems;

    this.setData({activeKey:e.detail})
    getMedicineLabel(label).then(res=>{
      labelItems = Object.assign({}, res.Disease_Left_Right)
      this.setData({labelItems})
    })
  },

  // 跳转到详情页
  medicineDetail(e){
    let label = e.currentTarget.dataset.label;
    wx.navigateTo({
      url:`infomation?label=${label}`
    })
  }
})